package com.wigball.java.jchef.model.common.methods;

import com.wigball.java.jchef.model.common.methods.impl.AddMethod;
import com.wigball.java.jchef.model.common.methods.impl.CleanMethod;
import com.wigball.java.jchef.model.common.methods.impl.CombineMethod;
import com.wigball.java.jchef.model.common.methods.impl.DivideMethod;
import com.wigball.java.jchef.model.common.methods.impl.FoldMethod;
import com.wigball.java.jchef.model.common.methods.impl.LiquefyMethod;
import com.wigball.java.jchef.model.common.methods.impl.MixMethod;
import com.wigball.java.jchef.model.common.methods.impl.PourMethod;
import com.wigball.java.jchef.model.common.methods.impl.PutMethod;
import com.wigball.java.jchef.model.common.methods.impl.RemoveMethod;
import com.wigball.java.jchef.model.common.methods.impl.StirMethod;
import com.wigball.java.jchef.model.common.methods.impl.TakeMethod;
import com.wigball.java.jchef.parser.ParserException;

public abstract class MethodFactory {

	public static Method fromString(String s) {
		
		if (s == null || "".equals(s.trim())) {
			return null;
		}
		
		Method m;
		
		if (s.startsWith("Take")) {
			m = new TakeMethod();
		}
		else if (s.startsWith("Put")) {
			m = new PutMethod();
		}
		else if (s.startsWith("Fold")) {
			m = new FoldMethod();
		}
		else if (s.startsWith("Add")) {
			m = new AddMethod();
		}
		else if (s.startsWith("Remove")) {
			m = new RemoveMethod();
		}
		else if (s.startsWith("Combine")) {
			m = new CombineMethod();
		}
		else if (s.startsWith("Divide")) {
			m = new DivideMethod();
		}
		else if (s.startsWith("Liquefy") || s.startsWith("Liquify")) {
			m = new LiquefyMethod();
		}
		else if (s.startsWith("Stir")) {
			m = new StirMethod();
		}
		else if (s.startsWith("Mix")) {
			m = new MixMethod();
		}
		else if (s.startsWith("Clean")) {
			m = new CleanMethod();
		}
		else if (s.startsWith("Pour")) {
			m = new PourMethod();
		}
		else {
			throw new ParserException("\"" + s + "\" is no known chef method!");
		}
		
		m.init(s);
		
		return m;
	}
	
}
